<?php

namespace App\Jobs\College;

use App\Service\Cruise\Mission\CollegeInputService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class AutoCloseExam implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private int $cruiseOrderId;
    private bool $updateOrder;

    /**
     * 自动关闭考试
     *
     * @return void
     */
    public function __construct(int $cruiseOrderId, bool $updateOrder = true)
    {
        $this->cruiseOrderId = $cruiseOrderId;
        $this->updateOrder = $updateOrder;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Log::info("AutoSubmitExam id: {$this->cruiseOrderId}");

        try {

            // 提交
            (new CollegeInputService($this->cruiseOrderId, 0))->clearValue()->submitOrder($this->updateOrder);
        } catch (\Exception $e) {
            Log::warning($e);
        }
    }
}
